<!DOCTYPE html>
<html>
<head>
	<title>dom1</title>
	<meta charset="utf-8">
</head>
<body>
	<input type="text" id="txt1">
	<input type="button" id="btn1" value="创建li">
	<ul id="ul1">
	</ul>
	<script type="text/javascript">
		window.onload = function(){
			var oBtn = document.getElementById("btn1")
			var oTxt = document.getElementById("txt1")
			var oUl = document.getElementById("ul1")

			oBtn.onclick=function(){
				var oLi = document.createElement("li")
				var aLi = oUl.getElementsByTagName("li")
				oLi.innerHTML=oTxt.value

				if(aLi.length == 0){
					oUl.appendChild(oLi);
				}else{
					oUl.insertBefore(oLi,aLi[0])
				}
			}
		}
	</script>
</body>
</html>